from django.http                        import HttpResponseForbidden
from sitepal.sitemenu.actions.actions   import *
from sitepal.sitemenu.actions.base_view import BaseView

class SimpleView(BaseView):
    def __init__(self,action_handler=None,**kwargs):
        assert action_handler is None or callable(action_handler)
        BaseView.__init__(self,**kwargs)
        self._action_handler = action_handler or self.default_handler

    def default_handler(self,request,view):
        context = view.get_context(request,None)
        return view.response(request,context)

    def handle_get(self,request):
        if self.has_perm(ACTION_EXECUTE_VIEW,request.user):
            return self._action_handler(request,self)
        else:
            return HttpResponseForbidden()

    def handle_post(self,request):
        if self.has_perm(ACTION_EXECUTE_VIEW,request.user):
            return self._action_handler(request,self)
        else:
            return HttpResponseForbidden()

